package com.achievement.project.system.scoreBackup.controller;

import java.util.List;

import com.achievement.project.system.choose.service.ICourseChooseService;
import com.achievement.project.system.teacher.service.ITeacherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.achievement.framework.aspectj.lang.annotation.Log;
import com.achievement.framework.aspectj.lang.enums.BusinessType;
import com.achievement.project.system.scoreBackup.domain.ScoreBackup;
import com.achievement.project.system.scoreBackup.service.IScoreBackupService;
import com.achievement.framework.web.controller.BaseController;
import com.achievement.framework.web.domain.AjaxResult;
import com.achievement.common.utils.poi.ExcelUtil;
import com.achievement.framework.web.page.TableDataInfo;

/**
 * 成绩备份Controller
 *
 * @author zkai
 * @date 2021-05-02
 */
@Controller
@RequestMapping("/system/scoreBackup")
public class ScoreBackupController extends BaseController
{
    private String prefix = "system/scoreBackup";

    @Autowired
    private IScoreBackupService scoreBackupService;

    @Autowired
    private ITeacherService teacherService;

    @Autowired
    private ICourseChooseService courseChooseService;

    @RequiresPermissions("system:scoreBackup:view")
    @GetMapping()
    public String scoreBackup()
    {
        return prefix + "/scoreBackup";
    }

    /**
     * 查询成绩备份列表
     */
    @RequiresPermissions("system:scoreBackup:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScoreBackup scoreBackup)
    {
        startPage();
        List<ScoreBackup> list = scoreBackupService.selectScoreBackupList(scoreBackup);
        return getDataTable(list);
    }

    /**
     * 导出成绩备份列表
     */
    @RequiresPermissions("system:scoreBackup:export")
    @Log(title = "成绩备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScoreBackup scoreBackup)
    {
        List<ScoreBackup> list = scoreBackupService.selectScoreBackupListForExcel(scoreBackup);
        ExcelUtil<ScoreBackup> util = new ExcelUtil<ScoreBackup>(ScoreBackup.class);
        return util.exportExcel(list, "成绩备份数据");
    }

    /**
     * 新增成绩备份
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存成绩备份
     */
    @RequiresPermissions("system:scoreBackup:add")
    @Log(title = "成绩备份", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScoreBackup scoreBackup)
    {
        return toAjax(scoreBackupService.insertScoreBackup(scoreBackup));
    }

    /**
     * 修改成绩备份
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ScoreBackup scoreBackup = scoreBackupService.selectScoreBackupById(id);
        mmap.put("scoreBackup", scoreBackup);
        return prefix + "/edit";
    }

    /**
     * 修改保存成绩备份
     */
    @RequiresPermissions("system:scoreBackup:edit")
    @Log(title = "成绩备份", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScoreBackup scoreBackup)
    {
        return toAjax(scoreBackupService.updateScoreBackup(scoreBackup));
    }

    /**
     * 删除成绩备份
     */
    @RequiresPermissions("system:scoreBackup:remove")
    @Log(title = "成绩备份", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scoreBackupService.deleteScoreBackupByIds(ids));
    }
}
